#pragma once

#include "controlcenter_global.h"
#include "manipulatorbase.h"

#ifndef M_PI
# define M_PI       3.14159265358979323846
#endif

namespace ControlCenter
{
	class CONTROLCENTER_EXPORT RoamManipulator:public ManipulatorBase
	{
	public:
		RoamManipulator();
		bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter &aa);
		virtual void home(double);
		virtual void home(const osgGA::GUIEventAdapter&,osgGA::GUIActionAdapter&);
		void home(const osg::Vec3& eyevec,const osg::Vec3& centervec,const osg::Vec3& upvec);
		virtual void setLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up,float distance,bool rightaway);
		virtual void setLookAt(const osg::Vec3& vec,const osg::Vec3& rota,float upangle,float sideangle,float distancevalue,bool rightaway);
		virtual void getLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float& distance);
		//virtual void collisionEvent(CoreBase::Scene::CollisionData* collisiondata);
		//virtual void computeNewPositionPerFrame();
		virtual void computeInverseMatrixPerFrame();
		virtual void setByMatrix(const osg::Matrixd& matrix);
		virtual void setByInverseMatrix(const osg::Matrixd& matrix);
		virtual osg::Matrixd getMatrix() const;
		virtual osg::Matrixd getInverseMatrix() const;
		void keyDownInterface(unsigned int key,bool down);
		virtual void enableManipulator();
		virtual void disenableManipulator();
		void setConstHeight(const int height);
		virtual void setToolAction(ActionData* action);
	protected:
		virtual ~RoamManipulator();
		virtual void _frame();
		void calcMovement();
		
		virtual void mouseClick(const osgGA::GUIEventAdapter* ea0,const osgGA::GUIEventAdapter* ea1);
		virtual void mouseRelease(const osgGA::GUIEventAdapter* ea0,const osgGA::GUIEventAdapter* ea1);
		virtual void mouseDrag(const osgGA::GUIEventAdapter* ea0,const osgGA::GUIEventAdapter* ea1,
			const osgGA::GUIEventAdapter* key0,const osgGA::GUIEventAdapter* key1);
		virtual void keyDown(const osgGA::GUIEventAdapter* ea0,osgGA::GUIActionAdapter& us);
		virtual void keyUp(const osgGA::GUIEventAdapter* ea0,osgGA::GUIActionAdapter& us);

		float _sideStep;
		float _forwardStep;
		float _upStep;
		float _cameraHeight;
		float _upDisctence;
		float _rightMouseRotationRate;
		float _leftMouseRotationRate;
		//double _collisionForwardSpeed;
		//double _collisionSideSpeed;
		//double _UFOframeNum;
		//double _curFrameNum;
		//std::vector<CoreBase::Scene::CollisionData> _allCollisionDataPerFrame;
		bool _isMoving;
		float _constForwardSpeed;
		float _constSideSpeed;
		double _directionRotationRate;
		double _directionRotationEpsilon;
		//osg::Matrix _offset;
		osg::Matrix _inverseMatrix;
		osg::Vec3 _direction;
		osg::Vec3 _preDirection;
		osg::Vec3 _eyeVecInterpolation;
		osg::Vec3 _centerVecInterpolation;
		osg::Vec3 _upVecInterpolation;
		osg::Vec3 _position;
		osg::Vec3 _composeDirection;
		int _moveFrameNum;
		float _forwardSpeed;
		float _sideSpeed;
		float _speed;
		float _upSpeed;
		osg::Vec3		_collisionOffsetVec3;
		int								_constHeight;
	};
}